﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using WmWebSystem.Models;
using WmWebSystem.Service;
using WmWebSystem.DbHelper;

namespace WmWebSystem.Controllers
{
    public class AttentionController : Controller
    {
        WmDb mydb = new WmDb();
        //
        // GET: /Attention/

        public ActionResult Index()
        {
            return View();
        }

        public void Create(int id, FormCollection collection)
        {
            var pro = mydb.Projects.Find(id);
            AttentionHelper.AddNewFansToAttentions(pro.ProjectNo, pro.ProjectName);
            pro.AttentionNum++;
            try
            {
                UpdateModel(pro);
                mydb.SaveChanges();
                //将记录写入日志
                string p1 = "Add new attention to AttentionNum, Now the AttentionNum=" + pro.AttentionNum + " The ProjectNo:" + pro.ProjectNo;
                WriteLog.WriteSysLog(p1);
            }
            catch (FieldAccessException ex)
            {
                //失败，进行回滚操作  记录异常
                WriteLog.WriteSysLog(ex.ToString());
            }
        }


    }
}
